
// index.html

// 打开登陆
function showLogin() {
    document.getElementById('mask').style.display = "inline";
}
// 关闭登陆
function closeLogin() {
    document.getElementById('mask').style.display = "none";
}

// 校验登陆
function isValiUser() {
    $.ajax({
        type: 'GET',    //get请求无法附带data：json数据
        url: 'control/loginstatus.php',
        success: function (result) {
            if (result) {
                console.log("用户已登录");
                document.getElementById("show_login").innerHTML = result;
                document.getElementById("logout").style.display = "block";
            } else {
                console.log("用户未登录");
            }
        }
    })
}

// 登陆
function loginUser() {
    var username = document.getElementById("username").value;
    var passwd = document.getElementById("passwd").value;

    if (username == "" || passwd == "") {
        document.getElementById("tips_null").style.display = "block";
    } else {
        $.ajax({
            type: 'POST',
            url: 'control/login.php',
            data: {
                "username": username,
                "passwd": passwd,
            },
            dataType: 'json',
            success: function (result) {
                if (result) {
                    alert("登陆成功");
                    window.location.href = "./";
                } else {
                    document.getElementById("tips_errno").style.display = "block";
                }
            }
        })
    }
}

// 注销
function logout() {
    $.ajax({
        type: "GET",
        url: "control/logout.php",
        success: function (result) {
            if (result) {
                document.getElementById("logout").style.display = "none";
                document.getElementById("show_login").innerHTML = "登陆";
                alert("注销成功");
            } else {
                alert("注销失败");
            }
        }
    })
}


// resumelist.html

function isValiAdmin() {
    $.ajax({
        type: 'GET',    //get请求无法附带data：json数据
        url: 'control/adminstatus.php',
        success: function (result) {
            if (result) {
                console.log("用户已登录");
            } else {
                console.log("用户未登录");
                window.location.href = "./";
            }
        }
    })
}

// 获取resume列表
function resumeList(){
    $.ajax({
        type: "GET",
        url: "control/c_resumelist.php",
        success: function (result){
            // var res = "{"+result+"}"
            // alert(res);
            document.getElementById("list").innerHTML = result;
        }
    })
}

// 删除指定resume
function deleteResume(id){
    if(confirm("确认删除？")){
        $.ajax({
            type: "POST",
            url: "control/c_deleteResume.php",
            dataType: "json",
            data: {
                "id": id
            },
            success: function(result){
                if(result){
                    alert("删除成功");
                    document.location.reload();
                }else{
                    alert("删除失败");
                    document.location.reload();
                }
            }
        })
    }
}